USE [Olive]
GO
PRINT N'Dropping DF_ContactBU_OptInModifiedDT...';


GO
ALTER TABLE [Core].[ContactBU] DROP CONSTRAINT [DF_ContactBU_OptInModifiedDT];


GO
PRINT N'Dropping DF_Domain_ModifiedDT...';


GO
ALTER TABLE [Core].[Domain] DROP CONSTRAINT [DF_Domain_ModifiedDT];


GO
PRINT N'Dropping DF_Domain_SiteTitle...';


GO
ALTER TABLE [Core].[Domain] DROP CONSTRAINT [DF_Domain_SiteTitle];


GO
PRINT N'Dropping DF_Domain_IsMultiBUYN...';


GO
ALTER TABLE [Core].[Domain] DROP CONSTRAINT [DF_Domain_IsMultiBUYN];


GO
PRINT N'Dropping DF_Domain_SMTPAllowSendYN...';


GO
ALTER TABLE [Core].[Domain] DROP CONSTRAINT [DF_Domain_SMTPAllowSendYN];


GO
PRINT N'Dropping DF_Domain_EnableSelfRegisterYN...';


GO
ALTER TABLE [Core].[Domain] DROP CONSTRAINT [DF_Domain_EnableSelfRegisterYN];


GO
PRINT N'Dropping DF_Domain_ThemeId...';


GO
ALTER TABLE [Core].[Domain] DROP CONSTRAINT [DF_Domain_ThemeId];


GO
PRINT N'Dropping DF_Domain_SubscriptionLevel...';


GO
ALTER TABLE [Core].[Domain] DROP CONSTRAINT [DF_Domain_SubscriptionLevel];


GO
PRINT N'Dropping DF_Domain_IsDroppedYN...';


GO
ALTER TABLE [Core].[Domain] DROP CONSTRAINT [DF_Domain_IsDroppedYN];


GO
PRINT N'Dropping DF_Domain_CreateDT...';


GO
ALTER TABLE [Core].[Domain] DROP CONSTRAINT [DF_Domain_CreateDT];


GO
PRINT N'Dropping DF_Domain_DomainId...';


GO
ALTER TABLE [Core].[Domain] DROP CONSTRAINT [DF_Domain_DomainId];


GO
PRINT N'Dropping FK_MainMenu_Domain...';


GO
ALTER TABLE [Core].[MainMenu] DROP CONSTRAINT [FK_MainMenu_Domain];


GO
PRINT N'Dropping FK_BusinessUnit_Domain...';


GO
ALTER TABLE [Core].[BusinessUnit] DROP CONSTRAINT [FK_BusinessUnit_Domain];


GO
PRINT N'Dropping FK_File_Domain...';


GO
ALTER TABLE [Core].[File] DROP CONSTRAINT [FK_File_Domain];


GO
PRINT N'Dropping FK_Domain_Theme...';


GO
ALTER TABLE [Core].[Domain] DROP CONSTRAINT [FK_Domain_Theme];


GO
PRINT N'Dropping PK_ContactBU_1...';


GO
ALTER TABLE [Core].[ContactBU] DROP CONSTRAINT [PK_ContactBU_1];


GO
PRINT N'Dropping [oliveuser]...';


GO
DROP USER [oliveuser];


GO
PRINT N'Creating [OliveLiteAppUser]...';


GO
CREATE USER [OliveLiteAppUser] WITHOUT LOGIN;


GO
PRINT N'Altering [Core].[ContactBU]...';


GO
ALTER TABLE [Core].[ContactBU] ALTER COLUMN [OptInModifiedDT] DATETIME NOT NULL;


GO
PRINT N'Creating PK_ContactBU...';


GO
ALTER TABLE [Core].[ContactBU]
    ADD CONSTRAINT [PK_ContactBU] PRIMARY KEY CLUSTERED ([ContactBusinessUnitId] ASC) WITH (ALLOW_PAGE_LOCKS = ON, ALLOW_ROW_LOCKS = ON, PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF, STATISTICS_NORECOMPUTE = OFF);


GO
PRINT N'Starting rebuilding table [Core].[Domain]...';


GO
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;

SET XACT_ABORT ON;

BEGIN TRANSACTION;

CREATE TABLE [Core].[tmp_ms_xx_Domain] (
    [DomainId]               UNIQUEIDENTIFIER CONSTRAINT [DF_Domain_DomainId] DEFAULT (newid()) ROWGUIDCOL NOT NULL,
    [DomainName]             NVARCHAR (127)   NOT NULL,
    [SiteTitle]              NVARCHAR (127)   CONSTRAINT [DF_Domain_SiteTitle] DEFAULT ('') NOT NULL,
    [IsMultiBUYN]            NCHAR (1)        CONSTRAINT [DF_Domain_IsMultiBUYN] DEFAULT (N'N') NOT NULL,
    [SMTPFrom]               NVARCHAR (127)   NULL,
    [SMTPServer]             NVARCHAR (127)   NULL,
    [SMTPPort]               NVARCHAR (5)     NULL,
    [SMTPUseSSLYN]           NCHAR (1)        NULL,
    [SMTPAccount]            NVARCHAR (127)   NULL,
    [SMTPPassword]           NVARCHAR (127)   NULL,
    [SMTPAllowSendYN]        NCHAR (1)        CONSTRAINT [DF_Domain_SMTPAllowSendYN] DEFAULT (N'N') NOT NULL,
    [EnableSelfRegisterYN]   NCHAR (1)        CONSTRAINT [DF_Domain_EnableSelfRegisterYN] DEFAULT (N'N') NOT NULL,
    [ThemeId]                UNIQUEIDENTIFIER CONSTRAINT [DF_Domain_ThemeId] DEFAULT ('{00000000-0000-0000-0000-000000000000}') NOT NULL,
    [MobileThemeId]          UNIQUEIDENTIFIER NULL,
    [ReCaptchaPublicKey]     NVARCHAR (127)   NULL,
    [ReCaptchaPrivateKey]    NVARCHAR (127)   NULL,
    [GoogleAnalyticsAccount] NVARCHAR (127)   CONSTRAINT [DF_Domain_GoogleAnalyticsAccount] DEFAULT (N'') NOT NULL,
    [PrimaryBU]              UNIQUEIDENTIFIER NOT NULL,
    [SubscriptionLevel]      NCHAR (1)        CONSTRAINT [DF_Domain_SubscriptionLevel] DEFAULT (N'F') NOT NULL,
    [IsDroppedYN]            NCHAR (1)        CONSTRAINT [DF_Domain_IsDroppedYN] DEFAULT (N'N') NOT NULL,
    [CreateDT]               DATETIME         CONSTRAINT [DF_Domain_CreateDT] DEFAULT (getdate()) NOT NULL,
    [CreatedById]            UNIQUEIDENTIFIER NOT NULL,
    [CreatedByName]          NVARCHAR (127)   NOT NULL,
    [ModifiedDT]             DATETIME         CONSTRAINT [DF_Domain_ModifiedDT] DEFAULT (getdate()) NOT NULL,
    [ModifiedById]           UNIQUEIDENTIFIER NOT NULL,
    [ModifiedByName]         NVARCHAR (127)   NOT NULL
);

ALTER TABLE [Core].[tmp_ms_xx_Domain]
    ADD CONSTRAINT [tmp_ms_xx_clusteredindex_PK_Domain] PRIMARY KEY CLUSTERED ([DomainId] ASC) WITH (ALLOW_PAGE_LOCKS = ON, ALLOW_ROW_LOCKS = ON, PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF, STATISTICS_NORECOMPUTE = OFF);

IF EXISTS (SELECT TOP 1 1
           FROM   [Core].[Domain])
    BEGIN
        INSERT INTO [Core].[tmp_ms_xx_Domain] ([DomainId], [DomainName], [SiteTitle], [IsMultiBUYN], [SMTPFrom], [SMTPServer], [SMTPPort], [SMTPUseSSLYN], [SMTPAccount], [SMTPPassword], [SMTPAllowSendYN], [EnableSelfRegisterYN], [ThemeId], [MobileThemeId], [ReCaptchaPublicKey], [ReCaptchaPrivateKey], [PrimaryBU], [SubscriptionLevel], [IsDroppedYN], [CreateDT], [CreatedById], [CreatedByName], [ModifiedDT], [ModifiedById], [ModifiedByName])
        SELECT   [DomainId],
                 [DomainName],
                 [SiteTitle],
                 [IsMultiBUYN],
                 [SMTPFrom],
                 [SMTPServer],
                 [SMTPPort],
                 [SMTPUseSSLYN],
                 [SMTPAccount],
                 [SMTPPassword],
                 [SMTPAllowSendYN],
                 [EnableSelfRegisterYN],
                 [ThemeId],
                 [MobileThemeId],
                 [ReCaptchaPublicKey],
                 [ReCaptchaPrivateKey],
                 [PrimaryBU],
                 [SubscriptionLevel],
                 [IsDroppedYN],
                 [CreateDT],
                 [CreatedById],
                 [CreatedByName],
                 [ModifiedDT],
                 [ModifiedById],
                 [ModifiedByName]
        FROM     [Core].[Domain]
        ORDER BY [DomainId] ASC;
    END

DROP TABLE [Core].[Domain];

EXECUTE sp_rename N'[Core].[tmp_ms_xx_Domain]', N'Domain';

EXECUTE sp_rename N'[Core].[tmp_ms_xx_clusteredindex_PK_Domain]', N'PK_Domain', N'OBJECT';

COMMIT TRANSACTION;

SET TRANSACTION ISOLATION LEVEL READ COMMITTED;


GO
PRINT N'Creating [Core].[Domain].[IX_Domain_Name]...';


GO
CREATE UNIQUE NONCLUSTERED INDEX [IX_Domain_Name]
    ON [Core].[Domain]([DomainName] ASC) WITH (ALLOW_PAGE_LOCKS = ON, ALLOW_ROW_LOCKS = ON, PAD_INDEX = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, IGNORE_DUP_KEY = OFF, STATISTICS_NORECOMPUTE = OFF, ONLINE = OFF, MAXDOP = 0)
    ON [PRIMARY];


GO
PRINT N'Creating [Content].[Forum]...';


GO
CREATE TABLE [Content].[Forum] (
    [ForumId]                  UNIQUEIDENTIFIER ROWGUIDCOL NOT NULL,
    [BusinessUnitId]           UNIQUEIDENTIFIER NOT NULL,
    [Parent]                   UNIQUEIDENTIFIER NULL,
    [ForumHomePageId]          UNIQUEIDENTIFIER NOT NULL,
    [Name]                     NVARCHAR (127)   NOT NULL,
    [Description]              NVARCHAR (1000)  NULL,
    [OnMainMenuYN]             NCHAR (1)        NOT NULL,
    [AllowAnonymousCommentsYN] NCHAR (1)        NOT NULL,
    [LastActivityDT]           DATETIME         NOT NULL,
    [IsDroppedYN]              NCHAR (1)        NOT NULL,
    [CreateDT]                 DATETIME         NOT NULL,
    [CreatedById]              UNIQUEIDENTIFIER NOT NULL,
    [CreatedByName]            NVARCHAR (127)   NOT NULL,
    [ModifiedDT]               DATETIME         NOT NULL,
    [ModifiedById]             UNIQUEIDENTIFIER NOT NULL,
    [ModifiedByName]           NVARCHAR (127)   NOT NULL
);


GO
PRINT N'Creating PK_Forum...';


GO
ALTER TABLE [Content].[Forum]
    ADD CONSTRAINT [PK_Forum] PRIMARY KEY CLUSTERED ([ForumId] ASC) WITH (ALLOW_PAGE_LOCKS = ON, ALLOW_ROW_LOCKS = ON, PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF, STATISTICS_NORECOMPUTE = OFF);


GO
PRINT N'Creating [Content].[ForumPost]...';


GO
CREATE TABLE [Content].[ForumPost] (
    [ForumPostId]    UNIQUEIDENTIFIER ROWGUIDCOL NOT NULL,
    [ForumId]        UNIQUEIDENTIFIER NOT NULL,
    [PageId]         UNIQUEIDENTIFIER NOT NULL,
    [Title]          NVARCHAR (100)   NOT NULL,
    [ContentText]    NVARCHAR (MAX)   NOT NULL,
    [AuthorId]       UNIQUEIDENTIFIER NOT NULL,
    [Email]          NVARCHAR (127)   NOT NULL,
    [PublishStatus]  NCHAR (1)        NOT NULL,
    [PublishDT]      NCHAR (10)       NOT NULL,
    [LastActivityDT] DATETIME         NOT NULL,
    [IsDroppedYN]    NCHAR (1)        NOT NULL,
    [CreateDT]       DATETIME         NOT NULL,
    [CreatedById]    UNIQUEIDENTIFIER NOT NULL,
    [CreatedByName]  NVARCHAR (127)   NOT NULL,
    [ModifiedDT]     DATETIME         NOT NULL,
    [ModifiedById]   UNIQUEIDENTIFIER NOT NULL,
    [ModifiedByName] NVARCHAR (127)   NOT NULL
);


GO
PRINT N'Creating PK_ForumPost...';


GO
ALTER TABLE [Content].[ForumPost]
    ADD CONSTRAINT [PK_ForumPost] PRIMARY KEY CLUSTERED ([ForumPostId] ASC) WITH (ALLOW_PAGE_LOCKS = ON, ALLOW_ROW_LOCKS = ON, PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF, STATISTICS_NORECOMPUTE = OFF);


GO
PRINT N'Creating [Content].[ForumPostComments]...';


GO
CREATE TABLE [Content].[ForumPostComments] (
    [ForumPostCommentId] UNIQUEIDENTIFIER ROWGUIDCOL NOT NULL,
    [ForumPostId]        UNIQUEIDENTIFIER NOT NULL,
    [PostedByName]       NVARCHAR (127)   NOT NULL,
    [ContactId]          UNIQUEIDENTIFIER NOT NULL,
    [Email]              NVARCHAR (127)   NOT NULL,
    [URL]                NVARCHAR (127)   NULL,
    [PublishStatus]      NCHAR (1)        NOT NULL,
    [ContentText]        NVARCHAR (MAX)   NOT NULL,
    [IsDroppedYN]        NCHAR (1)        NOT NULL,
    [CreateDT]           DATETIME         NOT NULL
);


GO
PRINT N'Creating PK_ForumPostComments...';


GO
ALTER TABLE [Content].[ForumPostComments]
    ADD CONSTRAINT [PK_ForumPostComments] PRIMARY KEY CLUSTERED ([ForumPostCommentId] ASC) WITH (ALLOW_PAGE_LOCKS = ON, ALLOW_ROW_LOCKS = ON, PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF, STATISTICS_NORECOMPUTE = OFF);


GO
PRINT N'Creating [Content].[ForumPostTags]...';


GO
CREATE TABLE [Content].[ForumPostTags] (
    [ForumPostTagId] UNIQUEIDENTIFIER ROWGUIDCOL NOT NULL,
    [ForumPostId]    UNIQUEIDENTIFIER NOT NULL,
    [TagId]          UNIQUEIDENTIFIER NOT NULL,
    [TagName]        NVARCHAR (127)   NOT NULL
);


GO
PRINT N'Creating PK_ForumPostTags...';


GO
ALTER TABLE [Content].[ForumPostTags]
    ADD CONSTRAINT [PK_ForumPostTags] PRIMARY KEY CLUSTERED ([ForumPostTagId] ASC) WITH (ALLOW_PAGE_LOCKS = ON, ALLOW_ROW_LOCKS = ON, PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF, STATISTICS_NORECOMPUTE = OFF);


GO
PRINT N'Creating [Content].[ForumTags]...';


GO
CREATE TABLE [Content].[ForumTags] (
    [ForumTagId] UNIQUEIDENTIFIER ROWGUIDCOL NOT NULL,
    [ForumId]    UNIQUEIDENTIFIER NOT NULL,
    [TagId]      UNIQUEIDENTIFIER NOT NULL,
    [TagName]    NVARCHAR (127)   NOT NULL
);


GO
PRINT N'Creating PK_ForumTags...';


GO
ALTER TABLE [Content].[ForumTags]
    ADD CONSTRAINT [PK_ForumTags] PRIMARY KEY CLUSTERED ([ForumTagId] ASC) WITH (ALLOW_PAGE_LOCKS = ON, ALLOW_ROW_LOCKS = ON, PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF, STATISTICS_NORECOMPUTE = OFF);


GO
PRINT N'Creating DF_ContactBU_OptInModifiedDT...';


GO
ALTER TABLE [Core].[ContactBU]
    ADD CONSTRAINT [DF_ContactBU_OptInModifiedDT] DEFAULT (getdate()) FOR [OptInModifiedDT];


GO
PRINT N'Creating DF_Forum_ForumId...';


GO
ALTER TABLE [Content].[Forum]
    ADD CONSTRAINT [DF_Forum_ForumId] DEFAULT (newid()) FOR [ForumId];


GO
PRINT N'Creating DF_Forum_IncludeOnMainMenuYN...';


GO
ALTER TABLE [Content].[Forum]
    ADD CONSTRAINT [DF_Forum_IncludeOnMainMenuYN] DEFAULT (N'N') FOR [OnMainMenuYN];


GO
PRINT N'Creating DF_Forum_AllowAnonymousCommentsYN...';


GO
ALTER TABLE [Content].[Forum]
    ADD CONSTRAINT [DF_Forum_AllowAnonymousCommentsYN] DEFAULT (N'N') FOR [AllowAnonymousCommentsYN];


GO
PRINT N'Creating DF_Forum_LastActivityDT...';


GO
ALTER TABLE [Content].[Forum]
    ADD CONSTRAINT [DF_Forum_LastActivityDT] DEFAULT (getdate()) FOR [LastActivityDT];


GO
PRINT N'Creating DF_Forum_IsDroppedYN...';


GO
ALTER TABLE [Content].[Forum]
    ADD CONSTRAINT [DF_Forum_IsDroppedYN] DEFAULT (N'N') FOR [IsDroppedYN];


GO
PRINT N'Creating DF_Forum_CreateDT...';


GO
ALTER TABLE [Content].[Forum]
    ADD CONSTRAINT [DF_Forum_CreateDT] DEFAULT (getdate()) FOR [CreateDT];


GO
PRINT N'Creating DF_Forum_ModifiedDT...';


GO
ALTER TABLE [Content].[Forum]
    ADD CONSTRAINT [DF_Forum_ModifiedDT] DEFAULT (getdate()) FOR [ModifiedDT];


GO
PRINT N'Creating DF_ForumPost_PublishDT...';


GO
ALTER TABLE [Content].[ForumPost]
    ADD CONSTRAINT [DF_ForumPost_PublishDT] DEFAULT (getdate()) FOR [PublishDT];


GO
PRINT N'Creating DF_ForumPost_LastActivityDT...';


GO
ALTER TABLE [Content].[ForumPost]
    ADD CONSTRAINT [DF_ForumPost_LastActivityDT] DEFAULT (getdate()) FOR [LastActivityDT];


GO
PRINT N'Creating DF_ForumPost_PublishStatus...';


GO
ALTER TABLE [Content].[ForumPost]
    ADD CONSTRAINT [DF_ForumPost_PublishStatus] DEFAULT (N'D') FOR [PublishStatus];


GO
PRINT N'Creating DF_ForumPost_ForumPostId...';


GO
ALTER TABLE [Content].[ForumPost]
    ADD CONSTRAINT [DF_ForumPost_ForumPostId] DEFAULT (newid()) FOR [ForumPostId];


GO
PRINT N'Creating DF_ForumPost_IsDroppedYN...';


GO
ALTER TABLE [Content].[ForumPost]
    ADD CONSTRAINT [DF_ForumPost_IsDroppedYN] DEFAULT (N'N') FOR [IsDroppedYN];


GO
PRINT N'Creating DF_ForumPost_CreateDT...';


GO
ALTER TABLE [Content].[ForumPost]
    ADD CONSTRAINT [DF_ForumPost_CreateDT] DEFAULT (getdate()) FOR [CreateDT];


GO
PRINT N'Creating DF_ForumPostComments_ForumPostCommentId...';


GO
ALTER TABLE [Content].[ForumPostComments]
    ADD CONSTRAINT [DF_ForumPostComments_ForumPostCommentId] DEFAULT (newid()) FOR [ForumPostCommentId];


GO
PRINT N'Creating DF_ForumPostComments_PublishStatus...';


GO
ALTER TABLE [Content].[ForumPostComments]
    ADD CONSTRAINT [DF_ForumPostComments_PublishStatus] DEFAULT (N'D') FOR [PublishStatus];


GO
PRINT N'Creating DF_ForumPostComments_IsDroppedYN...';


GO
ALTER TABLE [Content].[ForumPostComments]
    ADD CONSTRAINT [DF_ForumPostComments_IsDroppedYN] DEFAULT (N'N') FOR [IsDroppedYN];


GO
PRINT N'Creating DF_ForumPostTags_ForumPostTagId...';


GO
ALTER TABLE [Content].[ForumPostTags]
    ADD CONSTRAINT [DF_ForumPostTags_ForumPostTagId] DEFAULT (newid()) FOR [ForumPostTagId];


GO
PRINT N'Creating DF_ForumTags_ForumTagId...';


GO
ALTER TABLE [Content].[ForumTags]
    ADD CONSTRAINT [DF_ForumTags_ForumTagId] DEFAULT (newid()) FOR [ForumTagId];


GO
PRINT N'Creating FK_MainMenu_Domain...';


GO
ALTER TABLE [Core].[MainMenu] WITH NOCHECK
    ADD CONSTRAINT [FK_MainMenu_Domain] FOREIGN KEY ([DomainId]) REFERENCES [Core].[Domain] ([DomainId]) ON DELETE NO ACTION ON UPDATE NO ACTION;


GO
PRINT N'Creating FK_BusinessUnit_Domain...';


GO
ALTER TABLE [Core].[BusinessUnit] WITH NOCHECK
    ADD CONSTRAINT [FK_BusinessUnit_Domain] FOREIGN KEY ([DomainId]) REFERENCES [Core].[Domain] ([DomainId]) ON DELETE NO ACTION ON UPDATE NO ACTION;


GO
PRINT N'Creating FK_File_Domain...';


GO
ALTER TABLE [Core].[File] WITH NOCHECK
    ADD CONSTRAINT [FK_File_Domain] FOREIGN KEY ([DomainId]) REFERENCES [Core].[Domain] ([DomainId]) ON DELETE NO ACTION ON UPDATE NO ACTION;


GO
PRINT N'Creating FK_Domain_Theme...';


GO
ALTER TABLE [Core].[Domain] WITH NOCHECK
    ADD CONSTRAINT [FK_Domain_Theme] FOREIGN KEY ([ThemeId]) REFERENCES [Core].[Theme] ([ThemeId]) ON DELETE NO ACTION ON UPDATE NO ACTION;


GO
PRINT N'Creating FK_ForumPost_Forum...';


GO
ALTER TABLE [Content].[ForumPost] WITH NOCHECK
    ADD CONSTRAINT [FK_ForumPost_Forum] FOREIGN KEY ([ForumId]) REFERENCES [Content].[Forum] ([ForumId]) ON DELETE NO ACTION ON UPDATE NO ACTION;


GO
PRINT N'Creating FK_ForumPostComments_ForumPost...';


GO
ALTER TABLE [Content].[ForumPostComments] WITH NOCHECK
    ADD CONSTRAINT [FK_ForumPostComments_ForumPost] FOREIGN KEY ([ForumPostId]) REFERENCES [Content].[ForumPost] ([ForumPostId]) ON DELETE NO ACTION ON UPDATE NO ACTION;


GO
PRINT N'Creating FK_ForumPostTags_ForumPost...';


GO
ALTER TABLE [Content].[ForumPostTags] WITH NOCHECK
    ADD CONSTRAINT [FK_ForumPostTags_ForumPost] FOREIGN KEY ([ForumPostId]) REFERENCES [Content].[ForumPost] ([ForumPostId]) ON DELETE NO ACTION ON UPDATE NO ACTION;


GO
PRINT N'Creating FK_ForumTags_Forum...';


GO
ALTER TABLE [Content].[ForumTags] WITH NOCHECK
    ADD CONSTRAINT [FK_ForumTags_Forum] FOREIGN KEY ([ForumId]) REFERENCES [Content].[Forum] ([ForumId]) ON DELETE NO ACTION ON UPDATE NO ACTION;


GO
PRINT N'Creating CK_Domain_EnableSelfRegisterYN...';


GO
ALTER TABLE [Core].[Domain] WITH NOCHECK
    ADD CONSTRAINT [CK_Domain_EnableSelfRegisterYN] CHECK ([EnableSelfRegisterYN]='N' OR [EnableSelfRegisterYN]='Y');


GO
PRINT N'Creating CK_Domain_IsDroppedYN...';


GO
ALTER TABLE [Core].[Domain] WITH NOCHECK
    ADD CONSTRAINT [CK_Domain_IsDroppedYN] CHECK ([IsDroppedYN]='N' OR [IsDroppedYN]='Y');


GO
PRINT N'Creating CK_Domain_SMTPUseSSLYN...';


GO
ALTER TABLE [Core].[Domain] WITH NOCHECK
    ADD CONSTRAINT [CK_Domain_SMTPUseSSLYN] CHECK ([SMTPUseSSLYN]='N' OR [SMTPUseSSLYN]='Y');


GO
PRINT N'Creating CK_Domain_SubscriptionLevel...';


GO
ALTER TABLE [Core].[Domain] WITH NOCHECK
    ADD CONSTRAINT [CK_Domain_SubscriptionLevel] CHECK ([SubscriptionLevel]='E' OR [SubscriptionLevel]='B' OR [SubscriptionLevel]='P' OR [SubscriptionLevel]='F');


GO
PRINT N'Creating CK_Forum_IsDropped...';


GO
ALTER TABLE [Content].[Forum] WITH NOCHECK
    ADD CONSTRAINT [CK_Forum_IsDropped] CHECK ([IsDroppedYN]='N' OR [IsDroppedYN]='Y');


GO
PRINT N'Creating CK_Forum_AllowAnonymousComments...';


GO
ALTER TABLE [Content].[Forum] WITH NOCHECK
    ADD CONSTRAINT [CK_Forum_AllowAnonymousComments] CHECK ([AllowAnonymousCommentsYN]='N' OR [AllowAnonymousCommentsYN]='Y');


GO
PRINT N'Creating CK_ForumPost_PublishStatus...';


GO
ALTER TABLE [Content].[ForumPost] WITH NOCHECK
    ADD CONSTRAINT [CK_ForumPost_PublishStatus] CHECK ([PublishStatus]='P' OR [PublishStatus]='D');


GO
PRINT N'Creating CK_ForumPost_IsDropped...';


GO
ALTER TABLE [Content].[ForumPost] WITH NOCHECK
    ADD CONSTRAINT [CK_ForumPost_IsDropped] CHECK ([IsDroppedYN]='N' OR [IsDroppedYN]='Y');


GO
PRINT N'Creating CK_ForumPostComments_PublishStatus...';


GO
ALTER TABLE [Content].[ForumPostComments] WITH NOCHECK
    ADD CONSTRAINT [CK_ForumPostComments_PublishStatus] CHECK ([PublishStatus]='P' OR [PublishStatus]='D');


GO
PRINT N'Creating CK_ForumPostComments_IsDropped...';


GO
ALTER TABLE [Content].[ForumPostComments] WITH NOCHECK
    ADD CONSTRAINT [CK_ForumPostComments_IsDropped] CHECK ([IsDroppedYN]='N' OR [IsDroppedYN]='Y');


GO
PRINT N'Checking existing data against newly created constraints';


GO
USE [Olive];


GO
ALTER TABLE [Core].[MainMenu] WITH CHECK CHECK CONSTRAINT [FK_MainMenu_Domain];

ALTER TABLE [Core].[BusinessUnit] WITH CHECK CHECK CONSTRAINT [FK_BusinessUnit_Domain];

ALTER TABLE [Core].[File] WITH CHECK CHECK CONSTRAINT [FK_File_Domain];

ALTER TABLE [Core].[Domain] WITH CHECK CHECK CONSTRAINT [FK_Domain_Theme];

ALTER TABLE [Content].[ForumPost] WITH CHECK CHECK CONSTRAINT [FK_ForumPost_Forum];

ALTER TABLE [Content].[ForumPostComments] WITH CHECK CHECK CONSTRAINT [FK_ForumPostComments_ForumPost];

ALTER TABLE [Content].[ForumPostTags] WITH CHECK CHECK CONSTRAINT [FK_ForumPostTags_ForumPost];

ALTER TABLE [Content].[ForumTags] WITH CHECK CHECK CONSTRAINT [FK_ForumTags_Forum];

ALTER TABLE [Core].[Domain] WITH CHECK CHECK CONSTRAINT [CK_Domain_EnableSelfRegisterYN];

ALTER TABLE [Core].[Domain] WITH CHECK CHECK CONSTRAINT [CK_Domain_IsDroppedYN];

ALTER TABLE [Core].[Domain] WITH CHECK CHECK CONSTRAINT [CK_Domain_SMTPUseSSLYN];

ALTER TABLE [Core].[Domain] WITH CHECK CHECK CONSTRAINT [CK_Domain_SubscriptionLevel];

ALTER TABLE [Content].[Forum] WITH CHECK CHECK CONSTRAINT [CK_Forum_IsDropped];

ALTER TABLE [Content].[Forum] WITH CHECK CHECK CONSTRAINT [CK_Forum_AllowAnonymousComments];

ALTER TABLE [Content].[ForumPost] WITH CHECK CHECK CONSTRAINT [CK_ForumPost_PublishStatus];

ALTER TABLE [Content].[ForumPost] WITH CHECK CHECK CONSTRAINT [CK_ForumPost_IsDropped];

ALTER TABLE [Content].[ForumPostComments] WITH CHECK CHECK CONSTRAINT [CK_ForumPostComments_PublishStatus];

ALTER TABLE [Content].[ForumPostComments] WITH CHECK CHECK CONSTRAINT [CK_ForumPostComments_IsDropped];


GO
